Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stepfunctions-tasks): support for APIGW API: Invoke #11565

Closed
wants to merge 8 commits into from
Closed

feat(stepfunctions-tasks): support for APIGW API: Invoke #11565

wants to merge 8 commits into from

Conversation

Sumeet-Badyal
Copy link
Contributor

@Sumeet-Badyal Sumeet-Badyal commented Nov 19, 2020

feat(stepfunctions-tasks): support for APIGW API: Invoke

Implementation

Update package @aws-cdk/aws-stepfunctions-tasks to include support for ApiGateway Invoke
API as per documentation here:
https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html

Includes support for the following Amazon Athena API calls:
Invoke

Closes #11565


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@gitpod-io
Copy link

gitpod-io bot commented Nov 19, 2020

@shivlaks
Copy link
Contributor

@pahud feel free to give the open PR a review as well!

Copy link
Contributor

@ayush987goyal ayush987goyal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change! Some comments.

packages/@aws-cdk/aws-stepfunctions-tasks/README.md Outdated Show resolved Hide resolved
Comment on lines 243 to 245
/**
* Retreive data from a server at the specified resource
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/**
* Retreive data from a server at the specified resource
*/
/** Retrieve data from a server at the specified resource */

Comment on lines 224 to 236
} else {
return {
Resource: integrationResourceArn('apigateway', 'invoke', this.integrationPattern),
Parameters: sfn.FieldUtils.renderObject({
ApiEndpoint: this.props.apiEndpoint,
Method: this.props.method,
Stage: this.props.stage,
Path: this.props.path,
AuthType: (this.props.authType ? this.props.authType.value : sfn.TaskInput.fromDataAt('$.AuthType').value) === '$' ? (this.props.authType ? this.props.authType.value : sfn.TaskInput.fromDataAt('$.AuthType').value) : 'NO_AUTH',
}),
};
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a lot of duplicated code in this control flow chain from the if on down. I think we can simplify this to be a lot more succinct. let's refactor this please!

@mergify mergify bot dismissed shivlaks’s stale review November 19, 2020 20:14

Pull request has been modified.

* hostname of an API Gateway URL
* @example {ApiId}.execute-api.{region}.amazonaws.com
*/
readonly apiEndpoint: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should not be needed anymore.

Copy link
Contributor

@shivlaks shivlaks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would also love if @nija-at could take a look since he's the primary maintainer of the api-gateway module


const invokeJob = new tasks.ApiGatewayInvoke(stack, 'Invoke APIGW', {
api: restApi,
apiEndpoint: restApi.restApiId,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why does this need to be an input parameter as well? you're already accepting the restApi as input

* hostname of an API Gateway URL
* @example {ApiId}.execute-api.{region}.amazonaws.com
*/
readonly apiEndpoint: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the endpoint can be inferred from the api so you shouldn't need to make this an input anymore

* }
* },
*/
readonly headers?: { [key: string]: any };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirming to ensure we have the right type here: "Headers.$" : "$.input" is not valid correct?
i.e. the entire headers field cannot be allocated to a field in the state input

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyone digging into this? Happy to try and help; looking forward to putting this functionality to use ;)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eikeon - happy to have your help here!! :)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this pretty much the sole remaining thing holding up this pull request? Can save some time to attempt to dig into this headers issue later today

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers here probably should be similar to input here: packages/@aws-cdk/aws-stepfunctions-tasks/test/start-execution.test.ts and packages/@aws-cdk/aws-stepfunctions-tasks/lib/start-execution.ts -- and they both have the same type. Gotta run for a few hours, but will trace how headers is being used in this pull request compared to other working examples.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

readonly headers?: { [key: string]: string[] }

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also see a string value in one of the examples on that doc page: readonly headers?: { [key: string]: string[] | string }


/**
* Name of the stage where the API is deployed to in API Gateway
* @default - Required for REST and $default for HTTP
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: be sure to describe what $default means as the user might find that information useful in determining whether they need to set it or not.


/**
* Authentication methods
* @default - NO_AUTH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @default - NO_AUTH
* @default AuthType.NO_AUTH

}

/**
* Gets the "execute-api" ARN
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think the doc string should be a little more informative than the method name. Perhaps describe what that ARN is / what it's used for, show an example of what it looks like, etc.


/**
* The authentication method used to call the endpoint
* @default NO_AUTH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enums don't have defaults, it's only where they're used that would

Suggested change
* @default NO_AUTH

* Stack verification steps:
* * aws stepfunctions start-execution --state-machine-arn <deployed state machine arn> : should return execution arn
* * aws stepfunctions describe-execution --execution-arn <exection-arn generated before> : should return status as SUCCEEDED and a query-execution-id
* * aws apigateway test-invoke-method --rest-api-id <value> --resource-id <value> --http-method <value>: should return the same response as the state machine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should return the same response as the state machine

nit: better to be explicit and clear about what that response is

Comment on lines +23 to +28
function helloCode(_event: any, _context: any, callback: any) {
return callback(undefined, {
statusCode: 200,
body: 'hello, world!',
});
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be a function? - why not just define it ahead of it's usage or inline it?

* Stack verification steps:
* * aws stepfunctions start-execution --state-machine-arn <deployed state machine arn> : should return execution arn
* * aws stepfunctions describe-execution --execution-arn <exection-arn generated before> : should return status as SUCCEEDED and a query-execution-id
* * aws apigateway test-invoke-method --rest-api-id <value> --resource-id <value> --http-method <value>: should return the same response as the state machine
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should the rest-api-id also be an output? same question for all the inputs here. steps should include where they retrieved from. you might need to add outputs to the stack if they're not easily available.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what you mean by this? I am not sure how to get the rest-api-id.

@mergify mergify bot dismissed shivlaks’s stale review December 3, 2020 19:28

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 9cd40c7
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@nija-at nija-at assigned nija-at and unassigned nija-at Dec 8, 2020
@ghost
Copy link

ghost commented Jan 17, 2021

Hi Guys, what's up with the feature ?

@shivlaks
Copy link
Contributor

shivlaks commented Mar 3, 2021

superseded by #13033

@mmcircle - efforts to land this have been resumed in a different PR (#13033). please follow that one for the current status of API Gateway service integration support.

@shivlaks shivlaks closed this Mar 3, 2021
mergify bot pushed a commit that referenced this pull request Mar 10, 2021
…PIs (#13033)

feat(stepfunctions-tasks): Support calling APIGW REST and HTTP APIs

Taking ownership of the original PR #11565 by @Sumeet-Badyal 

API as per documentation here:
https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html
https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-control-access-using-iam-policies-to-invoke-api.html


closes #11566
closes #11565


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
This was referenced Mar 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants